import { createSlice, PayloadAction } from '@reduxjs/toolkit';

export interface TopbarState {
  dialogOpen: boolean;
  dialogName: string;
  dialogMetadata: Record<string, any>;
  pageTransitionMode: boolean;
}

const initialState: TopbarState = {
  dialogOpen: false,
  dialogName: '',
  dialogMetadata: {},
  pageTransitionMode: false,
};

const topbarSlice = createSlice({
  name: 'topbar',
  initialState,
  reducers: {
    openTopbarDialog: (state, action: PayloadAction<{ name: string; metadata?: Record<string, any> }>) => {
      state.dialogOpen = true;
      state.dialogName = action.payload.name;
      state.dialogMetadata = action.payload.metadata || {};
    },
    closeTopbarDialog: (state) => {
      state.dialogOpen = false;
      state.dialogName = '';
      state.dialogMetadata = {};
    },
    setPageTransitionMode: (state, action: PayloadAction<boolean>) => {
      state.pageTransitionMode = action.payload;
    },
  },
});

export const { openTopbarDialog, closeTopbarDialog, setPageTransitionMode } = topbarSlice.actions;

export default topbarSlice.reducer;

